#include("../../comm/ListHead.html")
<div class="layui-fluid layui-anim layui-anim-scale">
    <div class="layui-row layui-col-space5">
        <div class="layui-col-md12 height-auto">
            <div class="layui-card">
                <div class="card-search SearchTable">
                    <div class="right">

                        <div class="layui-inline layui-input-wrap">
                            <span class="layui-input-prefix"><i class="layui-icon layui-icon-username"></i></span>
                            <input type="text" id="search_empid" lay-verify="required" placeholder="帐号" autocomplete="off"
                                   class="table-search-text width150">
                        </div>
                        <div class="layui-inline layui-input-wrap">
                            <span class="layui-input-prefix"><i class="layui-icon layui-icon-user"></i></span>
                            <input type="text" id="search_username" lay-verify="required" placeholder="姓名" autocomplete="off"
                                   class="table-search-text width200">
                        </div>
                        <button class="layui-btn layui-btn-warm layui-btn-sm" lay-event="DoSearch">
                            搜索
                        </button>
                    </div>
                    <i class="layui-icon layui-icon-slider"></i>
                    当前位置 > <span class="color_green">系统用户列表</span>
                </div>
                <div class="layui-card-body">
                    <table class="layui-hide" id="table_1" lay-filter="table_1"></table>

                    <script type="text/html" id="table_1_bar_title">
                        <div class="layui-btn-container">
                            <button class="layui-btn layui-btn-sm btn-add" lay-event="AddSystemUser">
                                <i class="layui-icon">&#xe608;</i> 添加新用户
                            </button>
                            <button class="layui-btn layui-btn-sm layui-btn-disabled" permission-one="btn-edit" lay-event="EditSystemUser">修改</button>
                            <button class="layui-btn layui-btn-sm layui-btn-disabled" permission-one="btn-del" lay-event="DelSystemUser">删除</button>
                            <button class="layui-btn layui-btn-sm layui-btn-disabled" permission-one="btn-change-13" lay-event="MoreButton">更多<i class="layui-icon layui-icon-down"></i></button>
                        </div>
                    </script>
                    <script type="text/html" id="table_1_bar_page">
                        <div class="table-tips">
                            <i class="layui-icon layui-icon-tips"></i>
                            <span id="bar_desc"></span>
                        </div>
                    </script>
                    <script type="text/html" id="table_1_bar1">
                        <div class="layui-btn-container">
                            <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="SetUserRole" alt="权限配置">权限</a>
                            <a class="layui-btn layui-btn-xs" lay-event="EditUser">编辑</a>
                            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="ResetPwd">重置密码</a>
                        </div>
                    </script>
                    <script type="text/html" id="checkboxTpl">
                        <input type="checkbox" lay-skin="switch" name="lock" msg="锁定用户帐户" value="{{d.emp_id}}" lay-text="锁|" lay-filter="lockUser" {{ d.lock_tag ? 'checked' : '' }}>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>

<script language="JavaScript">
    layui.use(['myTable', 'table', 'form', 'util', 'myTool', 'dropdown'], function () {
        myTable = layui.myTable, table = layui.table, form = layui.form, myTool = layui.myTool, dropdown = layui.dropdown;
        var $ = layui.$;
        tableindex = myTable.render({
            url: 'SysUserListApi', title: '系统用户表'
            , cols: [[
                {type: 'checkbox', width: 36, fixed: true}
                , {field: 'user_type_name', title: '用户类型', width: 70}
                , {field: 'emp_id', title: '用户ID', width: 80, sort: true}
                , {field: 'login_id', title: '登陆帐号', width: 120, color: '#0780cf'}
                , {field: 'user_name', title: '姓名', width: 100}
                , {field: 'dept_name', title: '所属部门', width: 100, hide: false}
                , {field: 'user_posts', title: '岗位', width: 140, hide: false}
                , {field: 'user_email', title: '工作邮箱', hide: false}
                , {field: 'user_phone', title: '手机号码', width: 120, hide: false}
                , {field: 'user_desc', title: '备注', hide: false}
                , {
                    field: 'pwd', title: '密码', width: 46, align: 'center', templet: function (d) {
                        if (d.pwd == '') {
                            return '';
                        } else {
                            return '<button class="layui-btn layui-btn-xs" style="width:40px;background-color:orangered">' + d.pwd + '</button>';
                        }
                    }
                }
                , {field: 'lock_tag', title: '锁定', templet: '#checkboxTpl', width: 80, align: 'center'}
                , {fixed: 'right', title: '操作', toolbar: '#table_1_bar1', width: 160, align: 'center'}
            ]]
            , page: true, limit: 10
            , done: function (res, curr, count) {
                $("#bar_desc").html("共开设用户 <span>" + count + "</span> 个");
            }
        });

        //搜索 和重载
        layui.util.event("lay-event", {
            DoSearch: function () {
                tableindex.reload({
                    where: {
                        like: {user_name: $("#search_username").val()}
                        , s: {login_id: $("#search_empid").val()}
                    }
                    , page: {curr: 1}
                });
            }
        });

        //头工具栏事件
        table.on('toolbar(table_1)', function (obj) {
            var that = this;
            myTool.toolbar(this, obj, {
                AddSystemUser: function () {
                    index = top.layer.open({
                        type: 2, offset: '80px', title: false,
                        area: ['800px', '580px'], content: ["sysuser/AddSystemUser", 'no']
                        , end: function () {
                            top.layer.closeAll();
                            tableindex.reload();
                        }
                    });
                }
                , EditSystemUser: function () {
                    layui.myTool.doSingleSelect(table.checkStatus('table_1'), {key: 'emp_id'}, function (data, keys) {
                        index = top.layer.open({
                            type: 2, offset: '80px', title: false, area: ['800px', '580px'],
                            content: ["sysuser/EditSystemUser?emp_id=" + keys, 'no'],
                            end: function () {
                                top.layer.closeAll();
                                tableindex.reload();
                            }
                        });
                    });
                }
                , DelSystemUser: function () {
                    layui.myTool.doSingleSelect(table.checkStatus('table_1'), {key: 'emp_id'}, function (data, keys) {
                        index = top.layer.confirm('你是否确认删除用户【' + data[0].user_name + '】', {icon: 3, title: '提示', offset: '100px'}, function (index2) {
                            layui.myTool.post('DelSystemUserApi', {emp_id: keys}, function (result) {
                                tableindex.reload();
                            });
                        });
                    });
                }
                , MoreButton: function () {
                    layui.myTool.doSingleSelect(table.checkStatus('table_1'), {key: 'emp_id'}, function (datas, keys) {
                        dropdown.render({
                            elem: that, show: true
                            , data: [{title: '权限配置', id: 'set'}, {title: '重置密码', id: 'pwd'}
                                , {title: '摸拟登陆', id: 'login'}, {title: '摸拟菜单', id: 'menu'}]
                            , click: function (data, othis) {
                                if (data.id === 'set') {
                                    index = top.layer.open({
                                        type: 2, offset: '100px', title: false, area: ['800px', '580px'],
                                        content: ["sysuser/SetUserRole?emp_id=" + datas[0].emp_id, 'no'],
                                        end: function () {
                                            top.layer.closeAll();
                                        }
                                    });
                                } else if (data.id === 'menu') {
                                    index = top.layer.open({
                                        type: 2, offset: '60px', title: ['查看用户有权限的菜单及活动【' + datas[0].user_name + '】', 'font-size:15px;'], area: ['1020px', '595px'],
                                        content: ["sysuser/UserMenuActivityList?emp_id=" + datas[0].emp_id, 'no'],
                                        end: function () {
                                            top.layer.closeAll();
                                        }
                                    });
                                } else if (data.id === 'login') {
                                    window.open("InitUserByRole?emp_id=" + datas[0].emp_id);
                                } else if (data.id === 'pwd') {
                                    index = top.layer.confirm('你是否确认重置【' + datas[0].user_name + '】密码为#(form.key??)', {
                                        icon: 3, title: '提示', offset: '150px'
                                    }, function (index2) {
                                        top.layer.closeAll();
                                        myTool.get('ResetPwdApi', {emp_id: datas[0].emp_id}, function (results) {
                                            top.layer.closeAll();
                                            tableindex.reload();
                                        });
                                    });
                                }
                            }
                            , align: 'left', className: 'site-dropdown', style: 'width:80px'
                        });
                    });
                }
            });
        });


        //监听行工具事件
        table.on('rowDouble(table_1)', function (obj) {
            top.layer.open({
                type: 2, offset: '80px', title: false, area: ['800px', '580px'],
                content: ["sysuser/EditSystemUser?emp_id=" + obj.data.emp_id, 'no'],
                end: function () {
                    top.layer.closeAll();
                    tableindex.reload();
                }
            });
        });
        //监听行工具事件
        table.on('tool(table_1)', function (obj) {
            myTool.tool(this, obj, {
                ResetPwd: function (data) {
                    index = top.layer.confirm('你是否确认重置【' + data.user_name + '】密码为#(form.key??)', {
                        icon: 3, title: '提示', offset: '150px'
                    }, function (index2) {
                        top.layer.closeAll();
                        myTool.get('ResetPwdApi', {emp_id: data.emp_id}, function (results) {
                            top.layer.closeAll();
                            tableindex.reload();
                        });
                    });
                }
                , EditUser: function (data) {
                    index = top.layer.open({
                        type: 2, offset: '80px', title: false, area: ['800px', '580px'],
                        content: ["sysuser/EditSystemUser?emp_id=" + data.emp_id, 'no'],
                        end: function () {
                            top.layer.closeAll();
                            tableindex.reload();
                        }
                    });
                }
                , SetUserRole: function (data) {
                    index = top.layer.open({
                        type: 2, offset: '100px', title: false, area: ['800px', '580px'],
                        content: ["sysuser/SetUserRole?emp_id=" + data.emp_id, 'no'],
                        end: function () {
                            top.layer.closeAll();
                        }
                    });
                }
            });
        });
        //监听锁定操作

        layui.form.on('switch(lockUser)', function (obj) {
            myTool.postMsg("LockUserApi", {emp_id: this.value, field: $(obj.elem).attr("field"), msg: $(obj.elem).attr("msg")}, function (result) {
                layer.tips(result.msg, obj.othis);
            });
        });
    });
</script>
#include("../../comm/Foot.html")
